package com.ftg.learn.demo;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;
import java.util.List;
import java.util.Map;

/**
 * @author 布衣
 */
public class Play {

    public static void main(String[] args) {
        String path = "config.xml";

        try{
            //图纸
            Reader reader = Resources.getResourceAsReader(path);
            //工人
            SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
            //工人建工厂
            SqlSessionFactory ssf = sqlSessionFactoryBuilder.build(reader);
            //工厂生产sqlsession
            SqlSession sqlSession = ssf.openSession();

            //sqlsession执行sql
            List<Map<String,Object>> list = sqlSession.selectList("teacher.selectTeacher");
            System.out.println(list);
            sqlSession.close();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

}
